/*
 * WifesGlobalState.java
 *
 * Created on March 27, 2007, 4:45 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package ai9hells.pgaibe.chapter2.westworldwithmessaging;

import ai9hells.pgaibe.common.fsm.State;
import ai9hells.pgaibe.common.messaging.Telegram;

/**
 *
 * @author andre.bandarra
 */
public class WifesGlobalState extends State<MinersWife>{
    public static final WifesGlobalState INSTANCE = new WifesGlobalState();
    /** Creates a new instance of WifesGlobalState */
    private WifesGlobalState() {
    }

    public void enter(MinersWife entity) {}

    public void execute(MinersWife entity) {
        if (Math.random() <= 0.1 && !entity.getStateMachine().isInState(VisitBathroom.INSTANCE)){
            entity.getStateMachine().changeState(VisitBathroom.INSTANCE);
        }
    }

    public void exit(MinersWife entity) {}

    public boolean onMessage(MinersWife entity, Telegram t) {
        switch(t.getMsg()){
            case MessageTypes.MSG_HI_HONEY_IM_HOME:
                entity.getStateMachine().changeState(CookStew.instance);
                return true;
            default: return false;
        }
    }
    
}
